<template>
  <div class="comment-reply">
    <van-nav-bar
      :title="
        comment.reply_count > 0 ? `有${comment.reply_count}条回复` : '暂无回复'
      "
    >
      <van-icon slot="left" name="cross" @click="$emit('close')"></van-icon>
    </van-nav-bar>
    <div class="scroll-wrap">
      <!-- 当前评论项 -->
      <contentItem :comment="comment"></contentItem>
      <!-- 全部回复 -->
      <van-cell title="全部回复"></van-cell>

      <!-- 评论列表 -->
      <commentList :source="comment.com_id" type="c"  :list='commentList'></commentList>
    </div>
    <!-- 发布评论 -->
    <div class="post-wrap">
      <van-button class="post-btn" @click="isPostshow = true"
        >写评论</van-button
      >
    </div>
    <!-- 发布回复评论弹出层 -->
    <van-popup v-model="isPostshow" position="bottom">
      <commentPost
      :target="comment.com_id"
      @post-success='onPostSucess'
      ></commentPost>
    </van-popup>
  </div>
</template>

<script>
import contentItem from "@/components/comment-item";
import commentList from "@/views/article/commentList.vue";
import commentPost from "@/views/article/commentPost.vue";
export default {
  components: {
    contentItem,
    commentList,
    commentPost,
  },
  data() {
    return {
      isPostshow: false,
      commentList:[]
    };
  },
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  methods:{
      onPostSucess(data){
// 更新回复的数量
this.comment.reply_count++
// 关闭弹层
this.isPostshow=false
// 将最新的内容展示到列表的顶部
this.commentList.unshift(data.new_obj)
      }
  }
};
</script>

<style lang='less' scoped>
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  overflow-y: auto;
}
</style>